package com.abeir.bilibili.utils;

public final class Sundry {

    static final char[] INVALID_CHARACTERS = new char[] {
      '\\', '/', ':', '*', '?', '"', '<', '>', '|'
    };

    public static String safePath(String path) {
        if(path == null)
            return null;
        return path.replace("\\\\", "/").replace('\\', '/');
    }

    public static String safeFilename(String filename){
        if (filename == null)
            return null;
        char[] chars = filename.toCharArray();
        for(int i = 0; i < chars.length; i++){
            for (char invalidChar : INVALID_CHARACTERS) {
                if (chars[i] == invalidChar) {
                    chars[i] = '_';
                    break;
                }
            }
        }
        return String.valueOf(chars);
    }
}
